package com.sfzy.controller;

import com.github.pagehelper.PageInfo;
import com.sfzy.entity.ClassQaQuestion;
import com.sfzy.entity.Course;
import com.sfzy.service.ClassQaQuestionService;
import com.sfzy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("classQaQuestion")
public class ClassQaQuestionController {
    @Autowired
    private ClassQaQuestionService classQaQuestionService;
    //增
    @PostMapping
   public R add(@RequestBody ClassQaQuestion classQaQuestion) {
        int i = classQaQuestionService.addClassQaQuestion(classQaQuestion);
        if(i!=0){
            return R.ok();
        }
        return R.fail();
    }
    //改
    @PutMapping
    public R update(@RequestBody ClassQaQuestion classQaQuestion) {
        int i = classQaQuestionService.updateClassQaQuestion(classQaQuestion);
        if(i!=0){
            return R.ok();
        }
        return R.fail();
    }
    //删
    @DeleteMapping("{id}")
    public R delete(@PathVariable("id") int id){
        int i = classQaQuestionService.deleteClassQaQuestionById(id);
        if(i!=0){
            return R.ok();
        }
        return R.fail();
    }

    //id查
    @GetMapping("{id}")
    public R selectById(@PathVariable("id") int id){
        ClassQaQuestion qaQuestions = classQaQuestionService.getClassQaQuestionById3(id);
        return R.ok(qaQuestions);

    }
    //分页
    @GetMapping("page3")
    public R getByPage(ClassQaQuestion classQaQuestion,
                       @RequestParam(required = false,defaultValue = "1") int pageNum,
                       @RequestParam(required = false,defaultValue = "5") int pageSize){
        PageInfo<ClassQaQuestion> page = classQaQuestionService.getByPage3(classQaQuestion, pageNum, pageSize);
        return R.ok(page);
    }
}
